PROJECT(hello)
SET(TARGET demo)

# 指定生成存放可执行文件的目录
SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)

# 指定生成存放库文件的目录
SET(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib)

# 指定信赖cmake最小的版本号
CMAKE_MINIMUM_REQUIRED(VERSION 1.0)

# 将指定目录下所有源代码文件以列表形式存储到指定变量中
AUX_SOURCE_DIRECTORY(src DIR_SRCS)

ADD_EXECUTABLE(${TARGET} ${DIR_SRCS})

# 定义target信赖的其他target,确保编译本target之前,其他target已经被构建 
# ADD_DEPENDENCIES(${TARGET} depend-target1 depend-target2)

# 定义测试命令
ENABLE_TESTING()
#ADD_TEST(testname Exename arg1 arg2 ...)
ADD_TEST(demoTest ${PROJECT_BINARY_DIR}/bin/${TARGET})

# 向C/C++编译选项(CMAKE_C_FLAGS or CMAKE_CXX_FLAGS)
ADD_DEFINITIONS(-DENABLE_DEBUG -DMAX_NUM=10)

# 指定二进制、动态库和静态库安装
INSTALL(TARGETS ${TARGET}
	RUNTIME DESTINATION bin
	LIBRARY DESTINATION lib
	ARCHIVE DESTINATION libstatic)

# 指定普通文件安装
INSTALL(FILES COPYRIGHT README
	DESTINATION share/doc/${TARGET})

# 指定非目标文件的可执行程序安装
#INSTALL(PROGRAMS rundemo.sh
#	DESTINATION bin)

# 指定目录的安装
INSTALL(DIRECTORY doc/
	DESTINATION share/doc/${TARGET})

FIND_LIBRARY(cunitLib cunit)
IF(cunitLib)
	TARGET_LINK_LIBRARIES(${TARGET} ${cunitLib})
ENDIF(cunitLib)
